<template>
    <div class="bbox">
        <div class="head">
            <div class="input">
                <div class="box">
                    <div class="left">
                        <span class="iconfont icon-search"></span>
                    </div>
                    <div class="right">
                        <input type="text" placeholder="搜索关键词" />
                    </div>
                </div>
            </div>
            <div class="banner">
                <div class="box">
                    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="#007aff">
                        <van-swipe-item v-for="(item, index) in banner" :key="index">
                            <a :href="item.href">
                                <img v-lazy="item.src" alt="" />
                            </a>
                        </van-swipe-item>
                    </van-swipe>
                </div>
            </div>
            <div class="navs">
                <div @click.stop="goToDetail(item)" v-for="item in navs.items" :key="item.href" class="navs-item">
                    <img :src="item.src" alt="" />
                    <span class="name">{{ item.name }}</span>
                </div>
            </div>
        </div>
        <black :height="black.height" :background="black.bgcolor"></black>
        <div class="gzh-box">
            <div class="img">
                <img :src="listgzh.logo" alt="" />
            </div>
            <div class="text">
                <p>{{ listgzh.name }}</p>
                <p>{{ listgzh.desc }}</p>
            </div>
            <div class="button">
                <div @click="show = true">关注</div>
            </div>
        </div>
        <div class="list-tab">
            <div class="head">
                <p>{{ listtitle }}</p>
                <p @click.stop="goToAllCourse">查看全部</p>
            </div>
            <listtab v-for="item in listtab" :key="item.id" :item="item"></listtab>
        </div>
        <div class="logo">
            <div class="img">
                <img src="http://h5.xiaomage.tech/static/img/watermark@2x.96361c4e.png" alt="" />
            </div>
        </div>
        <van-overlay :show="show">
            <div class="wrapper" @click="show = false" @click.stop>
                <div class="block">
                    <img class="right-img" src="http://h5.xiaomage.tech/static/img/topright.548189da.png" alt="" />
                    <div class="title">关注公众号</div>
                    <div class="img">
                        <img :src="listgzh.qrcode" alt="" />
                    </div>
                    <div class="txt">长按二维码识别或截图保存</div>
                </div>
            </div>
        </van-overlay>
        <footerv></footerv>
    </div>
</template>

<script>
import footerv from "@/components/FooTerv.vue";
import black from "@/components/LittleBlack.vue";
import listtab from "@/components/ListTab.vue";
import Vue from "vue";
import { Swipe, SwipeItem, Lazyload, Overlay } from "vant";
Vue.use(Swipe).use(SwipeItem).use(Lazyload).use(Overlay);
export default {
    data() {
        return {
            show: false,
            // 总数据
            blocks: [],
            // 导航数据
            navs: [],
            // 轮播图数据
            banner: [],
            // 公众号信息
            listgzh: [],
            // 列表信息
            listtab: [],
            listtitle: "",
            black: {},
        };
    },
    methods: {
        goToDetail: function (item) {
            this.$router.push({
                path: "/vod/detail",
                query: {
                    id: item.href.split("?")[1].split("=")[1],
                },
            });
        },
        //全部课程页面
        goToAllCourse: function () {
            this.$router.push({
                path: "/vod",
            });
        },
    },
    async created() {
        let res = await this.$request.get("/api/v2/viewBlock/page/blocks", {
            params: {
                platform: "h5",
                page_name: "h5-page-index",
            },
        });
        //总数据
        this.blocks = res.data;
        res.data.forEach((item) => {
            if (item.sign == "slider") {
                //轮播图数据
                this.banner = item.config_render;
            }
            if (item.sign === "grid-nav") {
                //导航数据
                this.navs = item.config_render;
            }
            if (item.sign == "h5-vod-v1") {
                // 列表数据
                this.listtab = item.config_render.items;
                this.listtitle = item.config_render.title;
            }
            if (item.sign == "h5-gzh-v1") {
                //公众号数据
                this.listgzh = item.config_render;
            }
            if (item.sign == "blank") {
                //黑条
                this.black = item.config_render;
            }
        });
    },
    components: {
        black,
        footerv,
        listtab,
    },
};
</script>

<style lang="less" scoped>
@keyframes donghua {
    from {
        transform: translateY(50px);
    }
    to {
        transform: translateY(0px);
    }
}

.van-swipe__indicator /deep/ {
    width: 8px;
    height: 8px;
}

.wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
}

.block {
    width: 200px;
    height: 236px;
    border-radius: 8px;
    background-color: #fff;
    position: relative;
    animation: donghua 0.2s linear;
    .right-img {
        position: absolute;
        top: 3px;
        right: 0;
        width: 64px;
        height: 67px;
    }
    .title {
        width: 100%;
        margin-top: 20px;
        height: 14px;
        font-size: 14px;
        font-weight: 500;
        color: #333;
        line-height: 14px;
        text-align: center;
    }
    .img {
        width: 100%;
        margin-top: 20px;
        height: 120px;
        display: flex;
        justify-content: center;
        img {
            width: 120px;
            height: 120px;
        }
    }
    .txt {
        width: 100%;
        margin-top: 20px;
        height: 12px;
        font-size: 12px;
        font-weight: 400;
        color: #999;
        line-height: 12px;
        text-align: center;
    }
}

.bbox {
    background: #fff;
    .head {
        width: 100%;
        background: #fff;
        .input {
            flex: 1;
            height: 50px;
            padding: 8px 15px;
            .box {
                background: #f5f5f5;
                width: 100%;
                height: 100%;
                border-radius: 15px;
                display: flex;
                .left {
                    width: 50px;
                    height: 100%;
                    display: flex;
                    justify-content: center;
                    align-items: center;
                    span {
                        color: #999999;
                        font-size: 20px;
                    }
                }
                .right {
                    flex: 1;
                    height: 100%;
                    input {
                        width: 100%;
                        height: 100%;
                        border: none;
                        font-size: 14px;
                        outline: none;
                        background: #f5f5f5;
                        border-top-right-radius: 15px;
                        border-bottom-right-radius: 15px;
                    }
                }
            }
        }
        .banner {
            width: 100%;
            height: 135px;
            padding: 10px 15px;
            .box {
                width: 100%;
                height: 100%;
                // background: yellow;
                border-radius: 10px;
                overflow: hidden;
                .my-swipe {
                    width: 100%;
                    height: 100%;
                    .van-swipe-item {
                        a {
                            img {
                                width: 100%;
                                height: 100%;
                            }
                        }
                    }
                }
            }
        }
        .navs {
            display: flex;
            padding: 0.133333rem;
            background-color: white;
            .navs-item {
                flex: 1;
                display: flex;
                flex-direction: column;
                align-items: center;
                justify-content: center;
                img {
                    height: 50px;
                    width: 50px;
                }

                .name {
                    font-size: 12px;
                }
            }
        }
    }
    .gzh-box {
        padding: 15px;
        display: flex;
        width: 100%;
        background: #fff;
        // height: ;
        .img {
            width: 50px;
            height: 50px;
            margin-right: 10px;
            border-radius: 50%;
            overflow: hidden;
            img {
                width: 100%;
                height: 100%;
            }
        }
        .text {
            flex: 1;
            p:nth-child(1) {
                font-size: 15px;
                margin-top: 5px;
            }
            p:nth-child(2) {
                margin-top: 8px;
                font-size: 12px;
                color: #999;
            }
        }
        .button {
            width: 58px;
            display: flex;
            align-items: center;
            div {
                width: 100%;
                height: 24px;
                color: #fff;
                background: #3ca7fa;
                display: flex;
                justify-content: center;
                align-items: center;
                border-radius: 12px;
                font-size: 14px;
            }
        }
    }
    .list-tab {
        width: 100%;
        margin-top: 10px;
        padding: 25px 15px 20px 15px;
        background: #fff;
        .head {
            height: 19px;
            margin-bottom: 25px;
            display: flex;
            justify-content: space-between;
            p:nth-child(1) {
                height: 100%;
                font-size: 19px;
                line-height: 19px;
                font-weight: 600;
            }
            p:nth-child(2) {
                font-size: 13px;
                color: #999;
            }
        }
    }
    .logo {
        width: 100%;
        height: auto;
        padding-top: 50px;
        padding-bottom: 103px;
        margin-bottom: 53px;
        text-align: center;
        .img {
            display: flex;
            justify-content: center;
            img {
                width: 115px;
                height: 42px;
            }
        }
    }
}
</style>
